// Bueno de Mesquita and Smith 2009 IO

// REPLICATION
clear
use "BDSM2009 IO Rep Data.dta"
summarize
display c(k)
mdesc
tabmiss
codebook rCCODE
codebook year
gen gdp_avg = (rgdpchA + rgdpchB)/2
summarize

sort rCCODE year
merge rCCODE year using LifeDeath
drop in 137413/151157

tsset dyad year
gen lnMultiAid=ln(1+MultiAid)
gen USlnMultiAid=US*lnMultiAid
gen ColdWar=(year<1990)
gen LwealthB=ln(L.rgdpchB) 
gen LwealthB2=(ln(L.rgdpchB))^2 
gen LWB=L.WB
gen LRB=L.RB
gen LSB=L.SB
gen LWB2=LWB^2
gen LRBWB=LWB*LRB
gen LRB2WB=LWB*LRB^2
gen LRBRA=LRB*RA
gen LWBRA=LWB*RA 
gen LWB2RA=LWB^2*RA
gen LRB2RA=LRB^2*RA
gen USLWB=US*LWB
gen USLWB2=US*LWB^2
gen USLRBWB=US*LWB*LRB
gen USLRB2WB=US*LWB*LRB^2
gen USLRBRA=US*LRB*RA
gen USLWBRA=US*LWB*RA 
gen USLWB2RA=US*LWB^2*RA
gen USLRB2RA=US*LRB^2*RA
gen LkgB=L.kgB
gen Ltrade=ln(L.trade+1) 
gen Ltau_glob=L.tau_glob
gen Ltau2=tau^2
gen Lbw=(LWB==1)
gen LRBbw=Lbw*LRB
gen LRB2bw=Lbw*LRB^2
gen LbwRA=Lbw*RA
gen USLbw=US*Lbw
gen USLRBbw=US*Lbw*LRB
gen USLRB2bw=US*Lbw*LRB^2
gen USLbwRA=US*Lbw*RA
gen USlnDIS=US*lnDIS
gen UScolony=US*colony
gen USLtau2=US*Ltau2 
gen LkgB2=LkgB^2
gen LRB2=LRB^2
gen lnPOPB2=lnPOPB^2
gen USRA=US*RA
gen USLRB=US*LRB
gen USLRB2=USLRB^2
gen USLwealthB=US*LwealthB
gen USLwealthB2=USLwealthB^2
gen USlnPOPB=US*lnPOPB
gen USlnPOPB2=USlnPOPB^2
gen USLkgB=US*LkgB
gen USLkgB2=USLkgB^2
gen USLLifeExp=US*LLifeExp
gen USColdWar=US*ColdWar
gen USLtrade=US*Ltrade
gen USLtau_glob=US*Ltau_glob

sort year
by year: egen LLifeDATA=count(LLifeE)
sort dyad year

//Table 1 Model 1
xtreg  lnGrossAid WA  RA LWB LWB2 LRB LRB2 lnPOPB lnDIS ColdWar colony US if AnyGrossAid==1 , fe i(rCCODE)
// keep if AnyGrossAid==1
codebook year
codebook rCCODE

mdesc  lnGrossAid WA  RA LWB LWB2 LRB LRB2 lnPOPB lnDIS ColdWar colony US
codebook year if e(sample)
codebook rCCODE if e(sample)

//Table 1 Model 2
xtreg  lnGrossAid WA  RA LWB LWB2 LwealthB LwealthB2 LkgB LkgB2 lnPOPB lnPOPB2 lnDIS ColdWar colony US if AnyGrossAid==1 , fe i(rCCODE)
mdesc  lnGrossAid WA  RA LWB LWB2 LwealthB LwealthB2 LkgB LkgB2 lnPOPB lnPOPB2 lnDIS ColdWar colony US
codebook year if e(sample)
codebook rCCODE if e(sample)

//Table 1 Model 3
xtreg  lnGrossAid WA  RA LWB LWB2 LRB  LRB2 lnPOPB LLifeExp lnDIS ColdWar colony    Ltrade Ltau_glob Ltau2 lnMultiAid US if AnyGrossAid==1 & LLifeDATA>1000 , fe i(rCCODE)
mdesc  lnGrossAid WA  RA LWB LWB2 LRB  LRB2 lnPOPB LLifeExp lnDIS ColdWar colony    Ltrade Ltau_glob Ltau2 lnMultiAid US
codebook year if e(sample)
codebook rCCODE if e(sample)

//Table 1 Model 4
xtreg  lnGrossAid WA  RA LWB LWB2  LwealthB LwealthB2   lnPOPB lnPOPB2 LkgB LkgB2  LLifeExp lnDIS ColdWar colony Ltrade Ltau_glob Ltau2 lnMultiAid US USRA USLWB USLWB2  USLwealthB USLwealthB2  USlnPOPB USlnPOPB2   USLkgB USLkgB2 USLLifeExp  USlnDIS USColdWar UScolony USLtrade USLtau_glob USLtau2 USlnMultiAid if AnyGrossAid==1 & LLifeDATA>1000 , fe i(rCCODE)
mdesc  lnGrossAid WA  RA LWB LWB2  LwealthB LwealthB2   lnPOPB lnPOPB2 LkgB LkgB2  LLifeExp lnDIS ColdWar colony Ltrade Ltau_glob Ltau2 lnMultiAid US USRA USLWB USLWB2  USLwealthB USLwealthB2  USlnPOPB USlnPOPB2   USLkgB USLkgB2 USLLifeExp  USlnDIS USColdWar UScolony USLtrade USLtau_glob USLtau2 USlnMultiAid
codebook year if e(sample)
codebook rCCODE if e(sample)

// IMPUTATION
clear
use "BDSM2009 IO Imp Data.dta"
summarize

mi import flong, m(imp) id(year dyad) imp(TOTgross-US LifeExp-LLifeDATA)

sort dyad year

//Table 1 Model 1
mi estimate, post: xtreg  lnGrossAid WA  RA LWB LWB2 LRB LRB2 lnPOPB lnDIS ColdWar colony US if AnyGrossAid==1 , fe i(rCCODE)

//Table 1 Model 2
mi estimate, post: xtreg  lnGrossAid WA  RA LWB LWB2 LwealthB LwealthB2 LkgB LkgB2 lnPOPB lnPOPB2 lnDIS ColdWar colony US if AnyGrossAid==1 , fe i(rCCODE)

//Table 1 Model 3
mi estimate, esampvaryok post: xtreg  lnGrossAid WA  RA LWB LWB2 LRB  LRB2 lnPOPB LLifeExp lnDIS ColdWar colony    Ltrade Ltau_glob Ltau2 lnMultiAid US if AnyGrossAid==1 & LLifeDATA>1000 , fe i(rCCODE)

//Table 1 Model 4
mi estimate, esampvaryok post: xtreg  lnGrossAid WA  RA LWB LWB2  LwealthB LwealthB2   lnPOPB lnPOPB2 LkgB LkgB2  LLifeExp lnDIS ColdWar colony Ltrade Ltau_glob Ltau2 lnMultiAid US USRA USLWB USLWB2  USLwealthB USLwealthB2  USlnPOPB USlnPOPB2   USLkgB USLkgB2 USLLifeExp  USlnDIS USColdWar UScolony USLtrade USLtau_glob USLtau2 USlnMultiAid if AnyGrossAid==1 & LLifeDATA>1000 , fe i(rCCODE)
